package com.zhg.javakc.modules.purchase.controller;

/**
 * @author an
 * @version v0.0.1
 * @date 2019/11/22 20:12
 */

import com.zhg.javakc.base.page.Page;
import com.zhg.javakc.base.util.CommonUtil;
import com.zhg.javakc.modules.purchase.entity.PurchaseEntity;
import com.zhg.javakc.modules.purchase.service.PurchaseService;
import com.zhg.javakc.modules.supplier.entity.SupplierEntity;
import com.zhg.javakc.modules.supplier.service.SupplierService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

/**
 * 采购价表现层
 */

@Controller
@RequestMapping("/purchase")
public class PurchaseController {

    @Autowired
    PurchaseService purchaseService;

    @Autowired
    SupplierService supplierService;

    @RequestMapping("/query")
    public ModelAndView query(PurchaseEntity purchaseEntity, HttpServletRequest request, HttpServletResponse response)
    {

        ModelAndView modelAndView = new ModelAndView("purchase/list");
//        ModelAndView modelAndView = new ModelAndView();
        Page<PurchaseEntity> page = purchaseService.query(purchaseEntity,new Page<PurchaseEntity>(request,response));
        modelAndView.addObject("page",page);
        return modelAndView;
    }

    @RequestMapping("/create")
    public String insert(PurchaseEntity purchaseEntity){
        //采购价主键id
        purchaseEntity.setPriceId(CommonUtil.uuid());
        purchaseEntity.setPriceNumber("PL"+CommonUtil.uuid());
        purchaseService.save(purchaseEntity);
        return "redirect:query.do";
    }


    @RequestMapping("/querySupplier")
    @ResponseBody
    public List<Map<String,Object>> querySupplier(){
        List<Map<String,Object>> list = purchaseService.querySupplier();
        System.out.println(list);
        return list;
    }


}
